package test4_11.demo07;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Homework21_11 {
    public static void main(String[] args) throws Exception{
        Properties prop = new Properties();

        prop.setProperty("username", "admin");
        prop.setProperty("password", "123456");

        try (FileOutputStream fos = new FileOutputStream("a.txt")) {
            prop.store(fos, "用户登录信息");
            System.out.println("配置文件写入成功！");
        } catch (IOException e) {
            e.printStackTrace();
        }

        Properties prop1 = new Properties();

        // 1. 从文件加载配置
        try (FileInputStream fis = new FileInputStream("a.txt")) {
            prop1.load(fis);

            String username = prop1.getProperty("username");
            String password = prop1.getProperty("password");

            System.out.println("用户名: " + username);
            System.out.println("密码: " + password);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
